<template>
  <div class="base-container" id="main">
    <t-space direction="vertical">
      <t-form labelAlign="top" ref="form" :data="formData" :rules="rules" class="step-form table-form"
              labelWidth="140px">
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>年度</t-col>
          <t-col :span="2">
            <t-form-item label="年度" name="year">
              <t-select clearable v-model="formData.year" :options="yearOption" />
            </t-form-item>
          </t-col>
        </t-row>
      </t-form>
      <t-row>
        <t-col :span="1"></t-col>
        <t-col :span="10">
          <t-table
            rowKey="index"
            :data="data"
            :columns="columns"
            stripe
            table-layout="auto"
            size="small"
            hover
            tableLayout="fixed"
            bordered
            cellEmptyContent="-"
          >
            <template #name="{row}">
              <p :class="row.class">{{ row.name }}</p>
            </template>
            <template #num="{row}">
              <!-- :disabled="preData.inputDisabled.includes(row.num)" -->
              <t-input-number v-if="row.num !== ''" min="0" size="large" v-model="formData[`${row.num}`]"></t-input-number>
            </template>
            <template #footerSummary>
              <div class="t-table__row-filter-inner">
                说明：主要平衡关系：KX211≥ KX2111；KX221≥KX2211
              </div>
            </template>
          </t-table>
        </t-col>
        <t-col :span="1"></t-col>
      </t-row>
      <t-row style="margin-top: 20px;text-align: center">
        <t-col :span="12">
          <t-space :size="10">
            <t-button v-if="!isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(1)">{{
                applyLoading ? '提交中...' : '暂存'
              }}
            </t-button>
            <t-button v-if="!isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(2)">{{
                applyLoading ? '提交中...' : '提交'
              }}
            </t-button>
            <t-button v-if="isUpdate" theme="default" :loading="applyLoading" @click="onSubmit(3)">{{
                '取消'
              }}
            </t-button>
            <t-button v-if="isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(4)">{{
                applyLoading ? '修改中...' : '确认'
              }}
            </t-button>
          </t-space>
        </t-col>
      </t-row>
    </t-space>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
export default {
  name: "education-add-edit",
  dicts: [],
  components: {
  },
  data() {
    return {
      yearOption: [],
      file_domain: VITE_FILE_DOMAIN,
      deptMenuOptions: [],
      columns: [
        // { colKey: 'index', title: '序号', width: '100' },
        { colKey: 'name', title: '指标名称', },
        { colKey: 'code', title: '代码', align: "center" },
        { colKey: 'jldw', title: '计量单位', align: "center"},
        { colKey: 'num', title: '数量', align: "center"},
      ],
      rules: {
        projectName: [
          {
            required: true,
            message: "项目名称不能为空",
          }
        ],
      },
      data: [],
      preData: {
        name: [
          '一、师资队伍',
          '1.义务教育',
          '本校全职科学教师数量',
          '本校兼职科学教师数量',
          '当年科学教育外聘专家数量',
          '2.高中阶段教育',
          '本校全职科学教育教师数量',
          '本校兼职科学教育教师数量',
          '当年科学教育外聘专家数量',
          '3.高等教育',
          '本校全职科学教育教师数量',
          '本校兼职科学教育教师数量',
          '当年科学教育外聘专家数量',
          '二、教学情况',
          '1.义务教育阶段科学教育',
          '当年课程课时',
          '其中：当年校外课时',
          '当年学生数量',
          '2.高中阶段科学教育',
          '当年课程课时',
          '其中：当年校外课时',
          '当年学生数量',
          '3.高等科学教育人才培养',
          '当年本科专业学生数量',
          '当年研究生专业学生数量',
          '三、中小学科普（技）活动场所',
          '1.场所数量',
          '2.当年服务学生数量',
        ],
        code:[
          '—',
          '—',
          '人',
          '人',
          '人',
          '—',
          '人',
          '人',
          '人',
          '—',
          '人',
          '人',
          '人',
          '—',
          '—',
          '节',
          '节',
          '人',
          '—',
          '节',
          '节',
          '人',
          '—',
          '人',
          '人',
          '—',
          '个',
          '人',
        ],
        jldw: [
          '—',
          '—',
          'KX111',
          'KX112',
          'KX113',
          '—',
          'KX121',
          'KX122',
          'KX123',
          '—',
          'KX131',
          'KX132',
          'KX133',
          '—',
          '—',
          'KX211',
          'KX2111',
          'KX212',
          '—',
          'KX221',
          'KX2211',
          'KX222',
          '—',
          'KX231',
          'KX232',
          '—',
          'KX310',
          'KX320',
        ],
        num: [
          '',
          '',
          'ywjyqzjs',
          'ywjyjzjs',
          'ywjywpzjs',
          '',
          'gzjdqzjs',
          'gzjdjzjs',
          'gzjdwpzjs',
          '',
          'gdjyqzjs',
          'gdjyjzjs',
          'gdjywpzjs',
          '',
          '',
          'ywjykcks',
          'ywjyxwkcks',
          'ywjyxss',
          '',
          'gzjdkcks',
          'gzjdxwkcks',
          'gzjdxss',
          '',
          'gdjybkxss',
          'gdjyyjsxss',
          '',
          'zxxkphdcs',
          'zxxkphdfwxs',
        ],
        class: [
          '',
          'indent2',
          'indent3',
          'indent3',
          'indent3',
          'indent2',
          'indent3',
          'indent3',
          'indent3',
          'indent2',
          'indent3',
          'indent3',
          'indent3',
          '',
          'indent2',
          'indent3',
          'indent4',
          'indent6',
          'indent2',
          'indent3',
          'indent4',
          'indent6',
          'indent2',
          'indent3',
          'indent3',
          '',
          'indent2',
          'indent2',
        ],
        inputDisabled: []
      },
      applyLoading: false,
      formData: {
        localId: '',
        year: new Date().getFullYear(),
        kpjfcj: 0,
        zfbkcj: 0,
        kpzxjfcj: 0,
        jzcj: 0,
        zccj: 0,
        kpjfsy: 0,
        xzzcsy: 0,
        kphdzcsy: 0,
        kjhdzcsy: 0,
        kpcgzcsy: 0,
        zfbkzcsy: 0,
        kpzpzcsy: 0,
        qtzcsy: 0,
      },
      isUpdate: false,
    }
  },
  created() {
    for (let i = 2030; i >= 2000; i--) {
      this.yearOption.push({key: i, label: i.toString(), value: i.toString()})
    }
    const taskId = this.$route.params && this.$route.params.taskId;
    this.isUpdate = this.$route.query.isUpdate === 'true'
    Object.assign(this.formData, this.$route.query.currentRow)
    if (!taskId) {
      this.$message.error("缺少id");
      this.close();
      return false;
    }
    this.formData.localId = taskId

    for (let i = 0; i < this.preData.name.length; i++) {
      this.data.push({
        index: i + 1,
        name: this.preData.name[i],
        code: this.preData.code[i],
        jldw: this.preData.jldw[i],
        num: this.preData.num[i],
        class: this.preData.class[i]
      })
    }
  },
  methods: {
    onSubmit(type) {
      if (!this.formData.year) {
        this.$message.error('请选择年份！');
        return
      }
      if (type === 1) {
        this.$api.kpzh.education.add(this.formData).then(res => {
          this.$message.success('暂存成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/education/education-my"});
        })
      } else if (type === 2) {
        this.$api.kpzh.education.submit(this.formData).then(res => {
          this.$message.success('提交成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/education/education-my"});
        })
      } else if (type === 3) {
        this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/education/education-my"});
      } else if (type === 4) {
        this.$api.kpzh.education.update(this.formData).then(res => {
          this.$message.success('修改成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/education/education-my"});
        })
      } else {
        this.$message.error('type错误！');
      }
    },
    close() {
      this.$tab.closeOpenPage({path: "/kpzh/education/education-my"});
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .t-table__empty {
  min-height: initial;
}


</style>
